//==================================================================================================
/*
  EVE - Expressive Vector Engine
  Copyright : EVE Project Contributors
  SPDX-License-Identifier: BSL-1.0
*/
//==================================================================================================
#include "test.hpp"

#include <eve/module/bessel.hpp>

TTS_CASE_TPL ( "Check eve::cyl_bessel_y over real,  positive floating orders"
             , eve::test::scalar::ieee_reals
              )
<typename T>(tts::type<T>)
{
  auto constexpr N = 11;
  using a_t  = std::array<T, 8 >;
  using aN_t = std::array<a_t, N >;
  a_t re{ 2.9999999999999982e-01, 1.0000000000000000e+00, 1.7000000000000002e+00, 2.3999999999999995e+00,     3.0999999999999988e+00, 3.7999999999999998e+00, 4.4999999999999991e+00, 5.2000000000000002e+00};
  aN_t resN8;
  //res are taken from octave 9.2.0 bessely outputs
  int p=0;
  resN8[p] = a_t{-1.2133448538831417e+00,-2.7880164127599161e-01,2.1051516246798149e-01,4.4801874409797948e-01,4.4282921685168064e-01,2.5307460355209388e-01,-1.2886361627104936e-02,-2.3468223416684156e-01,};
  ++p; //1  1.333e+00
  resN8[p] = a_t{-3.7648698799182263e+00,-9.8505923573157550e-01,-4.7763681547602532e-01,-9.7339559780359325e-02,2.0798167807936299e-01,3.7718620111476947e-01,3.7413111225577933e-01,2.2207388693873825e-01,};
  ++p; //2  2.333e+00
  resN8[p] = a_t{-3.2252165189834493e+01,-2.3480229873415457e+00,-9.5974938282253186e-01,-5.5617381052060122e-01,-2.6392024646083084e-01,1.1617467405638876e-02,2.3459368740830755e-01,3.4856627875080992e-01,};
  ++p; //3  3.333e+00
  resN8[p] = a_t{-4.9793547751750742e+02,-9.9723813718623049e+00,-2.1569693334485711e+00,-9.8410951623192089e-01,-6.0528097382685031e-01,-3.6291913587977431e-01,-1.3084876975827542e-01,9.0742004247885893e-02,};
  ++p; //4  4.333e+00
  resN8[p] = a_t{-1.1032980668532542e+04,-6.4134519491740377e+01,-7.4989538856032256e+00,-2.1774637345680681e+00,-1.0377592671452986e+00,-6.4831770579120762e-01,-4.2844371667982650e-01,-2.3223037586890477e-01,};
  ++p; //5  5.333e+00
  resN8[p] = a_t{-3.1823261716897838e+05,-5.4586012088988764e+02,-3.6072991651979628e+01,-6.8789539697083253e+00,-2.2959814934610816e+00,-1.1157001931177162e+00,-6.9430209199546500e-01,-4.7779263069606048e-01,};
  ++p; //6  6.333e+00
  resN8[p] = a_t{-1.1303904518672930e+07,-5.7583734366670606e+03,-2.1884138589152386e+02,-2.8395665019691158e+01,-6.8623921082046611e+00,-2.4834723099778193e+00,-1.2173093902723875e+00,-7.4785707171275795e-01,};
  ++p; //7  7.333e+00
  resN8[p] = a_t{-4.7695773594902158e+08,-7.2393536743559540e+04,-1.5945098836181978e+03,-1.4298705585643944e+02,-2.5743900238988072e+01,-7.1625408401416788e+00,-2.7321984139564419e+00,-1.3439104927068111e+00,};
  ++p; //8  8.333e+00
  resN8[p] = a_t{-2.3306629852989143e+10,-1.0560134988022097e+06,-1.3537714472775311e+04,-8.4541412076966253e+02,-1.1493670579668537e+02,-2.5161422160744458e+01,-7.6876335885486098e+00,-3.0426597025885034e+00,};
  ++p; //9  9.333e+00
  resN8[p] = a_t{-1.2943358118745601e+12,-1.7527831443293273e+07,-1.3112818102594363e+05,-5.7279443383773305e+03,-5.9219537823781525e+02,-1.0319457389996556e+02,-2.5740518580668059e+01,-8.4082039386665972e+00,};
  ++p; //10  1.033e+01
  resN8[p] = a_t{-8.0513143886786344e+13,-3.2613017344267225e+08,-1.4263011360081737e+06,-4.3705264066609590e+04,-3.4509709481084401e+03,-4.8175929173382303e+02,-9.9087850894222626e+01,-2.7140636487496717e+01,};
  using eve::spherical;
  auto v0 = T(1.0/3.0);
  auto h =  eve::half(eve::as<T>());
  for(int j=0; j <= 7; ++j)
  {
    auto c = re[j];
    auto fac = eve::sqrt(eve::pio_2(eve::as(c))*eve::rec(c));
    for(int i=0; i < N; ++i)
    {
      auto v =  v0+i;
      auto res = resN8[i][j];
      TTS_RELATIVE_EQUAL(eve::bessel_y(v, c), res, tts::prec<T>());
      TTS_RELATIVE_EQUAL(eve::bessel_y[spherical](v, c), eve::bessel_y(v+h, c)*fac, tts::prec<T>());
    }
  }
};
